package cn.segment.core.seg;

/**
 * 前导初分词
 * @author Huang Yue
 * @version 创建时间：2010-6-9 上午10:55:26
 */
public class PreSeg extends SegBasic
{   
    public PreSeg(){
        super();
    }
    
    /**
     * 前导对句子分词具体方法
     */
    protected void lineSeg(WordTeam segResult, String str, int index){
        if(str == null || str.equals("")){
            return;
        }
        StringBuffer sb = new StringBuffer(str);
        
        for(int i = index ; i > 0 ; i--){
            if(dict.contains(sb.toString())){
                segResult.addWord(sb.toString()); 
                str = str.substring(i + 1);
                segResult.addScore(Math.log10(sb.length() * CONST_WORD));
                lineSeg(segResult, str, str.length() - 1);
                break;
            }
            sb.deleteCharAt(i);
        }
        
        if(sb.length() == 1){
            segResult.addWord(sb.toString());
            str = str.substring(1);
            segResult.addScore(Math.log10(CONST_CHAR));
            lineSeg(segResult, str, str.length() - 1);
        }
    }
}
